/*************************************************************************
    > File Name: Accountbook.cpp
    > Author: skylon
    > Site: blog.csdn.net/tcm_zhangpeng 
    > Created Time: 2016年05月15日 星期日 15时40分18秒
 ************************************************************************/

#include"Accountbook.h"

Accountbook::Accountbook()
{
	m_Account = vector<AccountItem>(100);
	m_AccountCount = 0;
}

short Accountbook::LoadAccountbook(ifstream &InputStream)
{
	short i;
	for (i = 0; i < 100; i++)
	{
		m_Account[i].Read(InputStream);
		if (InputStream.fail() != 0)
			break;
	}
	InputStream.close();
	m_AccountCount = i;
	return m_AccountCount;
}

AccountItem Accountbook::FindItem(string No_)
{
	short i;
	bool Found = false;
	for (i = 0; i < m_AccountCount; i++)
	{
		if (m_Account[i].GetNumber() == No_)
		{
			Found = true;
			break;
		}
	}
	if (Found == true)
		return m_Account[i];
	return AccountItem();
}

bool Accountbook::UpdateItem(AccountItem Item)
{
	string No_ = Item.GetNumber();
	short i;
	bool Found = false;

	for (i = 0; i < m_AccountCount; i++)
	{
		if (m_Account[i].GetNumber() == No_)
		{
			Found = true;
			break;
		}
	}
	if (Found == true)
		m_Account[i] = Item;
	return Found;
}

void Accountbook::StoreAccountbook(ofstream &OutputStream)
{
	short i;
	for (i = 0; i < m_AccountCount; i++)
	{
		m_Account[i].Write(OutputStream);
	}
	OutputStream.close();
	return ;
}

















